%{
/*
 * sr_parser.y:
 * Clunix, cezanne@clunix.com, 2005.3
 *
 * Copyright (c) 2005 by Clunix Inc. All Rights Reserved.
 */

#include "config.h"

#ifdef ECM_DEBUG
#define YYDEBUG	1
#else
#define YYDEBUG 0
#endif

#define YYSIZE_T	ecm_size_t

#define YYMALLOC	ecm_malloc
#define YYFREE		ecm_free

#include "sr.h"

typedef void *yyscan_t;

union YYSTYPE;

ECM_INLINE int srplex(union YYSTYPE *, yyscan_t scanner);

static void
srperror(yyscan_t scanner, sr_t **psr, char *msg)
{
}

%}

%pure_parser

%name-prefix="srp"

%parse-param { yyscan_t scanner }
%lex-param { yyscan_t scanner }
%parse-param { sr_t **psr }

%union {
	int	i_value;
	char	*s_value;
	ECMBOOL	bool;
	sr_val_t	val;
	sr_t	*sr;
       }

%start result

%token <i_value> Error ENDOFBUF
%token <s_value> String Identifier
%token <i_value> LeftAngle RightAngle
%token <i_value> LeftBrace RightBrace LeftDBrace RightDBrace
%token <i_value> Ampersand Semicolon Esterik

%type <sr>	result
%type <s_value>	literal alpha_numeric optional_name
%type <sr>	ASR ASR_stmts ASR_stmt ASR_block 
%type <sr>	ASRT ASRV optional_ASRV
%type <sr>	sr_ext optional_ext
%type <bool>	optional_homoset optional_ref

%%
result		: Error
		{
			YYERROR;
		}
		| ASR ENDOFBUF
		{
			*psr = $1;
			YYACCEPT;
		}
		;

ASR		: optional_name ASRT optional_ASRV optional_ext
		{
			$$ = asr_create_ASR($1, $2, $3, $4);
			if ($$ == NULL) {
				YYERROR;
			}
		}
		;

ASR_stmt	: ASR Semicolon;

optional_name	:
		{
			$$ = NULL;
		}
		| literal
		;

ASRT		: LeftAngle optional_ref Identifier optional_homoset RightAngle
		{
			$$ = asr_create_ASRT($3, $4, $2);
		}
		;

optional_homoset	:
		{
			$$ = ECM_FALSE;
		}
		| Esterik
		{
			$$ = ECM_TRUE;
		}
		;

optional_ref	:
		{
			$$ = ECM_FALSE;
		}
		| Ampersand
		{
			$$ = ECM_TRUE;
		}
		;

ASRV		: literal
		{
			$$ = sr_create_str(ST_STR, $1);
		}
		| ASR_block
		;

optional_ASRV	:
		{
			$$ = NULL;
		}
		| ASRV
		;

ASR_block	: LeftBrace ASR_stmts RightBrace
		{
			$$ = $2;
		}
		;

ASR_stmts	:
		{
			$$ = sr_create_dir();
		}
		| ASR_stmts ASR_stmt
		{
			sr_append($1, $2);
			$$ = $1;
		}
		;

optional_ext	:
		{
			$$ = NULL;
		}
		| sr_ext
		;

sr_ext		: LeftDBrace ASR RightDBrace
		{
			$$ = $2;
		}
		;

literal		: String | alpha_numeric;

alpha_numeric	: Identifier;

%%
